

import { defineStore } from "pinia";
import { reactive,ref,nextTick } from 'vue';
export const useWmsGlobal = defineStore("wmsGlobal",()=>{
  const menuData = reactive([])
  const isLogin = ref(true);
  const wmsOptions = reactive({});
  const dialogVisible = ref(false);
  const search = reactive({
    name:null,
    searchClientRef:null,
    searchCloseClients:null,
    searchGoodsRef:null,
    searchCloseGoods:null,
    searchStoreRef:null,
    searchStoreGoods:null
  });
  const getClient=(value)=>{
    dialogVisible.value = true;
    search.name = 'clients'
    
    return new Promise((resolve,reject)=>{
      nextTick(()=>{
        search.searchClientRef.open(value);
        const fn = (row)=>{
          resolve(row)
          dialogVisible.value = false;
        }
        search.searchCloseClients = fn
      })
    })
  }
  const getGoods=(value)=>{
    dialogVisible.value = true;
    search.name = 'goods'
    return new Promise((resolve,reject)=>{
      nextTick(()=>{
        search.searchGoodsRef.open(value);
        const fn = (row)=>{
          resolve(row)
          dialogVisible.value = false;
        }
        search.searchCloseGoods = fn
      })
    })
  }
  const getStore=(value)=>{
    dialogVisible.value = true;
    search.name = 'store'
    return new Promise((resolve,reject)=>{
      nextTick(()=>{
        search.searchStoreRef.open(value);
        const fn = (row)=>{
          resolve(row)
          dialogVisible.value = false;
        }
        search.searchCloseStore = fn
      })
    })
  }
  return {menuData,isLogin,wmsOptions,dialogVisible,search,getClient,getGoods,getStore}
})
